'use strict';

import { ajax, nameSpace} from 'utils/index';
import { Dialog } from 'qnui';

let ns = nameSpace('COMPONENT');
export const INIT_LIST = ns('INIT_LIST');
export const INIT_SHOP_TITLE_DATA = ns('INIT_SHOP_TITLE_DATA');

export function getData(params){
	  return (dispatch) => {
		ajax({
			  api: params.api,
			  method: 'GET',
			  data:params.params
			},(json) => {
				//json.data 格式： [{lable,value},{lable,value}]
				 dispatch({
					type: INIT_LIST,
					data_id:params.data_id,
					data: json.data,
					total:parseInt(json.total)
				  });
			},(json) => {
				  //失败后
				  //(json.code==53) W2超时
				Dialog.alert({content:"抱歉，获取页面插件失败，请重试"});
			});
	  }
}
export function setShopTitleData(params){
	return (dispatch) => {
		dispatch({
			type: INIT_SHOP_TITLE_DATA,
			data_id:params.data_id
	    });
	}
}